#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QDebug>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);


    // 设置根节点的三态属性
    ui->wives->setTristate(true);

    connect(ui->wives, &QCheckBox::clicked, this, [=](bool bl)
    {


        if(bl)
        {
            ui->jn->setChecked(true);
            ui->fy->setChecked(true);
            ui->ler->setChecked(true);
            ui->zr->setChecked(true);
            ui->mjp->setChecked(true);
            ui->sr->setChecked(true);
            ui->ak->setChecked(true);
        }
        else
        {
            ui->jn->setChecked(false);
            ui->fy->setChecked(false);
            ui->ler->setChecked(false);
            ui->zr->setChecked(false);
            ui->mjp->setChecked(false);
            ui->sr->setChecked(false);
            ui->ak->setChecked(false);
        }
    });

    connect(ui->jn, &QCheckBox::stateChanged, this, &MainWindow::statusChanged);
    connect(ui->fy, &QCheckBox::stateChanged, this, &MainWindow::statusChanged);
    connect(ui->ler, &QCheckBox::stateChanged, this, &MainWindow::statusChanged);
    connect(ui->zr, &QCheckBox::stateChanged, this, &MainWindow::statusChanged);
    connect(ui->mjp, &QCheckBox::stateChanged, this, &MainWindow::statusChanged);
    connect(ui->sr, &QCheckBox::stateChanged, this, &MainWindow::statusChanged);
    connect(ui->ak, &QCheckBox::stateChanged, this, &MainWindow::statusChanged);





}

MainWindow::~MainWindow()
{
    delete ui;
}


void MainWindow::on_radio_no996_stateChanged(int arg1)
{
    if(arg1 == Qt::Checked)
    {
        qDebug() << "不喜欢公司的996!!!";
    }
    else
    {
        qDebug() << "996忍一忍还是可以接收的...";
    }
}

void MainWindow::on_radio_nosalary_stateChanged(int arg1)
{

}

void MainWindow::on_radio_nogirl_stateChanged(int arg1)
{

}

void MainWindow::on_radio_nobeautiful_stateChanged(int arg1)
{

}

void MainWindow::statusChanged(int state)
{
    if(state == Qt::Checked)
    {
        m_number ++;
    }
    else
    {
        m_number --;
    }

    // 判断根节点是否需要做状态的更新
    if(m_number == 7)
    {
        ui->wives->setCheckState(Qt::Checked);
    }
    else if(m_number == 0)
    {
        ui->wives->setCheckState(Qt::Unchecked);
    }
    else
    {
        ui->wives->setCheckState(Qt::PartiallyChecked);
    }

}
